<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ReadBookmarksByTagCommand
 *
 * @author Manu
 */
require_once("mmw_command_Command.php");
require_once(dirname(__FILE__)."/../mapper/mmw_mapper_BookmarkMapper.php");
require_once(dirname(__FILE__)."/../controller/mmw_controller_Request.php");
require_once(dirname(__FILE__)."/../core/mmw_core_AppException.php");

class mmw_command_ReadBookmarksByTagCommand extends mmw_command_Command {
    public function doExecute(mmw_controller_Request $request) {
        if ($request->getProperty("key")==NULL) {
            throw new mmw_core_AppException("Missing parameter 'key'");
        }
        $keyword=$request->getProperty("key");
        
        $bookmarkMapper=new mmw_mapper_BookmarkMapper();
        $arBookmarks=$bookmarkMapper->findByTagLike($keyword);
        
        $request->setResults($arBookmarks);
        $request->addFeedback("Fetched ".count($arBookmarks)." bookmarks which tag matches '$keyword'");
        $request->setSuccess(true);
    }
}
//******************************************************Tests
//$readBookmarksByTagCommand=new ReadBookmarksByTagCommand();
//$request=new mmw_controller_Request();
//$request->setProperty("key","prog");
//
//$readBookmarksByTagCommand->doExecute($request);
?>
